package com.guo.boot.service.impl;

import com.guo.boot.entity.User;
import com.guo.boot.mapper.UserMapper;
import com.guo.boot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author HeartGuo
 * @date 2021/12/19 0019 - 18:46
 */
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;
    @Override
    public User login(String username, String password) {
        // 如果账号密码都对则返回登录的用户对象，若有一个错误则返回null
        User user = userMapper.selectByUnameAndPword(username,password);
        if(user!=null){
            // 重要信息置空
            user.setPassword("");
        }
        return user;
    }

    @Override
    public Integer register(User user) {
        Integer newUser = userMapper.insert(user);
        return newUser;
    }
}
